import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {
	
	private static final int MAX = 100000;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true) {
			String str = br.readLine();
			if(str.trim().equals("0")) {
				break;
			}
			
			int[] a = convertToIntArray(str);
			str = br.readLine();
			int[] b = convertToIntArray(str);
			 
			int[] aMemTable = new int[a.length];
			int[] bMemTable = new int[b.length];
			aMemTable[0] = a[0];
			bMemTable[0] = b[0];
			
			int indexa = 1, indexb = 1;
			while(true) {
				if(indexa == a.length && indexb == b.length) {
					break;
				}
				
				
				if((indexa == a.length ? Integer.MAX_VALUE : a[indexa]) <= (indexb == b.length ? Integer.MAX_VALUE : b[indexb])) {
					int index = search(b, a[indexa - 1], b.length - 1);
					if(index != -1) {
						aMemTable[indexa] = Math.max(bMemTable[index] + a[indexa], aMemTable[indexa - 1] + a[indexa]); 
					} else {
						aMemTable[indexa] = aMemTable[indexa - 1] + a[indexa];
					}
					indexa++;
				} else {
					int index = search(a, b[indexb - 1], a.length - 1);
					if(index != -1) {
						bMemTable[indexb] = Math.max(aMemTable[index] + b[indexb], bMemTable[indexb - 1] + b[indexb]); 
					} else {
						bMemTable[indexb] = bMemTable[indexb - 1] + b[indexb];
					}
					indexb++;
				}
			}
			System.out.println(Math.max(aMemTable[aMemTable.length - 1], bMemTable[bMemTable.length - 1]));
		}
	}
	
	private static int search(int[] a , int num, int j) {
		return search(a, num, 0, j);
	}
	
	private static int search(int[] a , int num, int i, int j) {
		if(i > j) {
			return -1;
		}
		int mid = (i + j) / 2;
		if(a[mid] == num) {
			return mid;
		} else if(a[mid] < num) {
			return search(a, num, mid + 1, j);
		} else {
			return search(a, num, i, mid - 1);
		}
	}
	
	private static int[] convertToIntArray(String str) {
		StringTokenizer sToken = new StringTokenizer(str, " ");
		int n = Integer.parseInt(sToken.nextToken());
		int[] a = new int[n + 2];
		for(int i = 1; i <= n; i++) {
			a[i] = Integer.parseInt(sToken.nextToken());
		}
		a[0] = -MAX;
		a[a.length - 1] = MAX;
		
		return a;
	}
}

